package com.grudesign.stutrip.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Po.BasecampPo;
import com.grudesign.stutrip.entity.Po.NewinfoPo;
import com.grudesign.stutrip.mapper.BasecampMapper;
import com.grudesign.stutrip.service.BasecampService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 基地营地表 服务实现类
 * </p>
 *
 * @author wx
 * @since 2022-05-09
 */
@Service
public class BasecampServiceImpl extends ServiceImpl<BasecampMapper, BasecampPo> implements BasecampService {

    @Override
    public Object getBases(String cur, String li) {
        Page<BasecampPo> page = new Page<>(Long.parseLong(cur),Long.parseLong(li));
        Page<BasecampPo> basePage = baseMapper.selectPage(page, Wrappers.emptyWrapper());
        return new ReturnInfo("200","ok").data("basesInfo",basePage);
    }

    @Override
    public Object getBases(long cur, long li, BasecampPo po) {
        if(po==null){
            return new ReturnInfo("200","ok").data("basesInfo",getBases(String.valueOf(cur),String.valueOf(li)));
        }
        String name = po.getName();
        Page<BasecampPo> poPage = new Page<>(cur,li);
        QueryWrapper <BasecampPo> wrapper = Wrappers.query();
        if(StringUtils.hasText(name)){
            wrapper.like("name",name);
        }
        Page<BasecampPo> poPage1 = baseMapper.selectPage(poPage, wrapper);
        return new ReturnInfo("200","ok").data("basesInfo",poPage1);
    }
}
